package com.atguigu.gmall.sms.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.zaxxer.hikari.HikariDataSource;

import io.seata.rm.datasource.DataSourceProxy;

@Configuration
public class DataSourceConfig {
    
    @Primary
    @Bean("dataSource")
    public DataSource dataSource(@Value("${spring.datasource.url}") String jdbcUrl,
        @Value("${spring.datasource.driver-class-name}") String driverClassName,
        @Value("${spring.datasource.username}") String userName,
        @Value("${spring.datasource.password}") String passWord) {
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setJdbcUrl(jdbcUrl);
        hikariDataSource.setDriverClassName(driverClassName);
        hikariDataSource.setUsername(userName);
        hikariDataSource.setPassword(passWord);
        return new DataSourceProxy(hikariDataSource);

    }
}
